package edu.colorado.karl.mainsched;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import edu.colorado.karl.databases.DatabaseUpdater;

/**
 * DatabaseThread is a thread that controls invocation of database updates. 
 */
public class DatabaseThread extends Thread {
	//	Used for log4j logging
	private static final Log log = LogFactory.getLog(DatabaseThread.class);
	
	/**
	 * Sole constructor.
	 */
	public DatabaseThread() {
		
	}
	
	/**
	 * Runs the database updating thread, which executes every 5 minutes.
	 */
	public void run() {
		DatabaseUpdater db = new DatabaseUpdater();
		while(true) {
			//	Do database update
			log.debug("Performing Database Update.");
			db.update();
			
			try {
				Thread.sleep(300000);	// 5 min cycle
//				Thread.sleep(15000);	// for testing
			} catch (InterruptedException e) {
				break;
			}
		}
	}
}
